package com.hzqc.wxaapp.rest;

import com.hzqc.wxaapp.sdk.*;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author xiafang
 * @since 2022/8/16 9:48
 */
@AllArgsConstructor
@RestController
@RequestMapping("/api/wxa")
public class WxaUrlController {
    private final WechatAppUrlSchemeService wechatAppUrlSchemeService;


    @CrossOrigin({"https://asset.hzqcjt.com"})
    @GetMapping("/scheme/{appId}")
    public ResponseEntity<UrlSchemeResponse> getUrlScheme(@PathVariable String appId) {
        UrlSchemeBody body = new UrlSchemeBody();
        body.setAppId(appId);
        body.setExpireType(UrlExpireType.DAY);
        body.setExpireInterval(25);
        UrlSchemeBody.JumpWxa jumpWxa = new UrlSchemeBody.JumpWxa();
        jumpWxa.setEnvVersion(EnvVersion.RELEASE);
        jumpWxa.setQuery("");
        jumpWxa.setPath("pages/home/haibao");
        body.setJumpWxa(jumpWxa);
        return ResponseEntity.ok(wechatAppUrlSchemeService.generateUrlScheme(body));
    }
    @Autowired
    MiniAppTokenStorage miniAppTokenStorage;
    @GetMapping("/tt")
    public void  test(){
        miniAppTokenStorage.put("aaaa","sdfasdf");
        String aaaa = miniAppTokenStorage.get("aaaa");
        System.out.println("aaaa = " + aaaa);
    }

}
